<?php
date_default_timezone_set('PRC'); #设置时区
class api_Abstract
{
    protected $_time = null;
            
    function __construct()
    {
        $this->_time = time();
        $this->_ymd = date('Y-m-d', $this->_time);
    }

    /**
     * @param $msg
     * @param $code
     * @param bool $is_success
     * @param bool $data
     * @return actionResultDO
     */
    protected function actionResultObject($msg, $code, $is_success = false, $data = false, $id_list = false)
    {
        $rtn->is_success = (bool) $is_success;
        $rtn->code = $code;
        $rtn->msg = $msg;
        if ($data !== false) {
            $rtn->data = $data;
        }
        if ($id_list) {
            $rtn->id_list = $id_list;
        }
        return $rtn;
    }
	/**
     * 取得与主站密码相同算法的密钥
     * @access private
     * @param type $length
     * @param type $type
     * @param type $hash
     * @return string
     */
    protected static function random($length, $type = 0, $hash = '') 
    {
        if ($type == 0) {
            $chars = '0123456789abcdefghijklmnopqrstuvwxyz';
        } else if ($type == 1) {
            $chars = '0123456789';
        } else if ($type == 2) {
            $chars = 'abcdefghijklmnopqrstuvwxyz';
        }
        $max = strlen($chars) - 1;
        mt_srand((double) microtime() * 1000000);
        for ($i = 0; $i < $length; $i++) {
            $hash .= $chars[mt_rand(0, $max)];
        }
        return $hash;
    }

    /**
     * 取得与主站相同算法的密码
     * @access private
     * @param type $password
     * @param type $salt
     * @return type
     */
    protected function dpassword($password, $salt)
    {
        /* 老平台转密码验证 */
        if ($salt == 'aa123456') {
            return '' === $password ? '' : md5(sha1($password) . '*]f)={.zRuS;FZWUv6"TGJPO_5g<Kx#~k&|7nj(I');
        } else {
            return md5((preg_match("/^[a-f0-9]{32}$/", $password) ? md5($password) : md5(md5($password))) . $salt);
        }
    }
	/**
	* 生成admin_reg
	*/
	protected function get_random($prefix = '') {
		return $prefix . base_convert(time() * 1000, 10, 36) . "_" . base_convert(microtime(), 10, 36) . uniqid();
	}
	 

}
